﻿/*
 * SimplePointRenderer
 * 
 * initial implementation : 20.10.2008
 *
 * Copyright (c) Adam Sida, asida@centrum.cz.
 * All rights reserved.
 * 
 * for license see Petra.Gis.License.txt
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using Petra.Gis.Geometry;
using Petra.Gis.Geometry.Support;
using Petra.Gis.DataServices;
using Petra.Gis.RenderingServices.PlanarBase;
using Petra.Gis.ReferenceSystemServices.Transformations;

namespace Petra.Gis.RenderingServices.GDIPlus
{
  /// <summary>
  /// renders point as 'dot' in map of defined size and color
  /// </summary>
  public partial class SimplePointRenderer : BitmapMapRendererBase
  {

    protected Pen _outpen;


    //public SimplePointRenderer(BitmapMap map, RenderStyle s)
    //  :base(map, s)
    //{

    //  //parse style

    //}




    public override void PrepareToRender()
    {
      base.PrepareToRender();

      _outpen = new Pen((Color)renderStyle["Color"], (int)renderStyle["PointSize"]);

    }
    




    /// <summary>
    /// method that implements drawing (conversion) of gis geometry into output format geometry
    /// </summary>
    /// <param name="geometry">any system type currently</param>
    public override void RenderGeometry(GeometryBase geometry)
    {

      _forwardTransform.Transform(geometry);

      //validate type against supported types
      if (geometry is Petra.Gis.Geometry.Point)
        renderPoint((Petra.Gis.Geometry.Point)geometry);

      else if (geometry is MultiPoint)
        foreach (Petra.Gis.Geometry.Point p in (MultiPoint)geometry)
          renderPoint(p);

      else if (geometry is GeometryCollection)
        foreach (GeometryBase g in (GeometryCollection)geometry)
          if (g is Petra.Gis.Geometry.Point)
            renderPoint((Petra.Gis.Geometry.Point)g);

    }



    protected virtual void renderPoint(Petra.Gis.Geometry.Point pg)
    {

      

      System.Drawing.Point p = ((DisplayTransformMatrix)((BitmapMap)rendererMap).RenderTransform).ProjectionToMap(pg.X, pg.Y);

      // if point falls into visible map area then draw
      if (getPointIntesectMask(p) == 0)
        _outGraphic.DrawEllipse(_outpen, p.X, p.Y, 0, 0);
    }




    public override DomainGeometryTypeEnum RendererGeometryDomain
    {
      get { return DomainGeometryTypeEnum.Point; }
    }



    public override bool IsRenderable(GeometryBase geometry)
    {
      //todo: update to linear only !!
      return true;
    }



  }
}
